// xc_lshop/shop/pack/mycard/infor.js
var actbill = require('../../model/pack_list')

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    xcmodel: null,
    loading: true,
    shareid: 0,
    statuscolor: {
      1: {
        name: '未使用',
        background: "#FCAB20"
      },
      2: {
        name: '使用中',
        background: "#30A75D"
      },
      3: {
        name: '已使用',
        background: "#848484"
      },
      '-1': {
        name: '已失效',
        background: "#CBCBCB"
      },
    },
  },
  xcloaddata: function (options, config) {
    // console.log(options)
    if (options.shareid) {
      this.setData({
        shareid: options.shareid
      })
    }
    this.getmodel(options.id)
  },
  showqrcode(e) {
    var item = e.currentTarget.dataset.item;
    if (item.status == 1 || item.status == 2) {
      this.selectComponent('#qrcode').init(item.id)

    }

  },
  getmodel(id) {
    var that = this;
    actbill.getmodel(id).then(res => {
      console.log("res")
      console.log(res['obj'])
      if (res['status'] == 1) {
        that.setData({
          loading: false,
          xcmodel: res['obj']
        })
      } else {
        that.error(res['message'], true)
      }

    })
  },
  exchange() {
    var item = this.data.xcmodel;
    this.selectComponent('#exchange').init(item)
  },
  //领取套餐卡
  getpack() {
    var app=getApp();

    console.log(this.data.shareid)
    var that = this;
    app.xc_sys_config.authop.oppower("login").then(function (res) {
      actbill.getpack(that.data.xcmodel.id, that.data.shareid).then(res => {
        console.log("res")
        console.log(res['obj'])
        if (res['status'] == 1) {
          wx.showToast({
            icon: "none",
            title: '领取成功',
          })
          wx.redirectTo({
            url: '/xc_lshop/shop/pack/mycard/infor?id=' + res['id'],
          })
          // that.setData({
          //   loading:false,
          //   xcmodel:res['obj']
          // })
        } else {
          that.error(res['message'], true)
        }

      })
    })

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    // var index=e.target.dataset.detail;
    var item = this.data.xcmodel
    console.log("onShareAppMessage")

    console.log(item)
    var app = getApp()
    var sharetitle = item.name

    var shareimg = item.simg


    // var sharepath =""

    var sharepath = "/xc_lshop/shop/pack/mycard/infor?id=" + item.id + "&shareid=" + app.globalData.member.member_id


    return {
      title: sharetitle,
      path: sharepath,
      imageUrl: shareimg
    }

  }
})